﻿<view:NavigationAwarePage 
    xmlns:view="clr-namespace:PhoneUtils.View;assembly=PhoneUtils"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:live="clr-namespace:Microsoft.Live.Controls;assembly=Microsoft.Live.Controls"    
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    x:Class="WPForms.Phone.View.SkyDriveBackup"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="800" d:DesignWidth="480"
    DataContext="{Binding SkyDriveBackup, Source={StaticResource ViewModelLocator}}">    
    <Grid x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="SkyDriveStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition From="SignedOut" GeneratedDuration="0:0:0.4" To="SignedIn"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="SignedOut">
                    <Storyboard>
                        <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="signedInGrid" d:IsOptimized="True"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="signedInGrid">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="SignedIn">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="signInGrid">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="signInGrid" d:IsOptimized="True"/>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="LoadingStates">
                <VisualState x:Name="ContentLoaded">
                    <Storyboard>
                        <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="loadingGrid" d:IsOptimized="True"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="loadingGrid">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Loading">
                    <Storyboard>
                        <DoubleAnimation Duration="0" To="0.295" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="mainContent" d:IsOptimized="True"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Control.IsEnabled)" Storyboard.TargetName="mainContent">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <System:Boolean>False</System:Boolean>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="{StaticResource AppName}" Style="{StaticResource PhoneTextNormalStyle}"/>
            <StackPanel Margin="9,-7,0,0" Orientation="Horizontal">
                <TextBlock Margin="0" Text="{Binding CurrentForm.Name}"  Style="{StaticResource PhoneTextTitle2Style}"/>                
                <TextBlock Margin="0" Text="skydrive backup" Style="{StaticResource PhoneTextTitle2Style}"/>
            </StackPanel>
        </StackPanel>
        <ContentControl Grid.Row="1" x:Name="mainContent" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
            <Grid>
                <Grid x:Name="signInGrid">
                    <live:SignInButton x:Name="signIn" Scopes="wl.signin wl.basic wl.skydrive wl.skydrive_update" ClientId="{StaticResource LiveClientId}" SessionChanged="SignIn_SessionChanged" VerticalAlignment="Center">            
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SessionChanged">
                                <i:InvokeCommandAction Command="{Binding SessionChangedCommand}" CommandParameter="{Binding ., ElementName=signIn}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </live:SignInButton>			
                </Grid>
                <Grid x:Name="signedInGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="1*"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="1" x:Name="currentPath"/>
                    <Button HorizontalAlignment="Left" Grid.Row="2" Margin="15" x:Name="upButton" Click="Up_Click" Visibility="Collapsed" BorderThickness="0">
                        <StackPanel Orientation="Horizontal">
                            <Image Width="40" Height="40" Margin="0 0 15 0" Source="/WPForms.Phone;component/Resources/Images/back.png"/>
                            <TextBlock Text="back"/>
                        </StackPanel>
                    </Button>
                    <ListBox Grid.Row="3" x:Name="folders" SelectionChanged="Folders_ItemSelected">
                        <ListBox.ItemTemplate>                            
                            <DataTemplate>
                                <ContentControl IsEnabled="{Binding IsEnabled}" Margin="15" HorizontalContentAlignment="Stretch">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="55"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <Image Height="40" Width="40" Source="{Binding IconSource}"/>
                                        <TextBlock VerticalAlignment="Center" Grid.Column="1" Text="{Binding Name}"/>                                    
                                        <Image Grid.Column="2" Grid.RowSpan="2" VerticalAlignment="Center" Height="40" Width="40" Source="{Binding ActionIconSource}"/>
                                    </Grid>
                                </ContentControl>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <Grid Grid.Row="4">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="filename:" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" x:Name="filename" Text="formsbackup"/>
                    </Grid>
                    <Button Grid.Row="5" x:Name="selectButton" Content="create backup here" IsEnabled="False" Click="SelectButton_Click"/>
                </Grid>		
            </Grid>	
        </ContentControl>
        <Grid Grid.Row="1" x:Name="loadingGrid">
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Loading..." FontSize="30"/>
        </Grid>
    </Grid>
</view:NavigationAwarePage>
